<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=building-width, initial-scale=1, maximum-scale=1">
    <% include("/templates/common/header.html"){} %>
    <!-- jqgrid-->
    <link href="${ctxPath!}/css/bootstrap.css?v=3.3.6" rel="stylesheet">
    <link href="${ctxPath!}/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="${ctxPath!}/jqgrid/jqgrid.css" rel="stylesheet">
    <style>
        .ui-jqgrid-btable tbody tr td{
            vertical-align: middle!important;
        }
    </style>
</head>
<body>
<div class="content-search">
    <div class="content-search">
        <form id="search" class="layui-form layui-form-pane" lay-filter="form">
            <div class="layui-inline" style="margin-left: 10px;">
                <div class="layui-input-inline">
                    <select name="workerLevel" id="workerLevel" lay-filter="workerLevel">
                        <option value="">请选择等级</option>
                        <%
                        for(workerLevel in workerLevels!){
                        %>
                        <option value="${workerLevel.id}">${workerLevel.name}</option>
                        <%
                        }
                        %>
                    </select>
                </div>
            </div>
            <div class="layui-inline" style="margin-left: 10px;">
                <div class="layui-input-inline">
                    <select name="education" id="education" lay-filter="education">
                        <option value="">请选择学历</option>
                        <%
                        for(education in educations!){
                        %>
                        <option value="${education.value}">${education.desc}</option>
                        <%
                        }
                        %>
                    </select>
                </div>
            </div>
            <div class="layui-inline" style="margin-left: 10px;">
                <div class="layui-input-inline">
                    <select name="free" id="free" lay-filter="education">
                        <option value="">请选择工作状态</option>
                        <option value="1">空闲</option>
                        <option value="0">忙碌</option>
                    </select>
                </div>
            </div>
            <div class="layui-inline" style="margin-left: 10px;padding: 12px;">
                <div class="layui-input-inline">
                    <input type="text" id="keyword" autocomplete="off" class="layui-input" placeholder="请输入关键字" onchange="search()">
                </div>
            </div>
            <div class="layui-inline">
                <atom:auth type="button" perm="sys:worker:edit"  iconText="&#xe615;" onclick="return search();" text=" 搜索"/>
            </div>
        </form>
    </div>

</div>
<!-- 内容主体区域 -->
<div style="padding: 2px;">
    <div class="jqGrid_wrapper">
        <table id="table"></table>
        <div id="pager" ></div>
    </div>
</div>
</div>
<script src="${ctxPath!}/jquery/jquery.min.js?v=2.2.4"></script>
<script src="${ctxPath!}/jquery/jquery.form.js?v=3.50.0"></script>
<script src="${ctxPath!}/jqgrid/i18n/grid.locale-cnffe4.js?0820"></script>
<script src="${ctxPath!}/jqgrid/jquery.jqGrid.minffe4.js?0820"></script>
<script src="${ctxPath!}/jqgrid/frozen.js?v=1.0.1"></script>
<script src="${ctxPath!}/jqgrid/myjqGrid.js"></script>
<script src="${ctxPath!}/layui/layui.js"></script>
<script>

    layui.use('form', function(){
    });

    var colNames = ["ID","职员名称" ,"籍贯","年龄","住址","邮箱","工作状态"];
    var colModel = [{
        name : "id",
        index : "id",
        width : 50,
        hidden: true,
        align : "left"
    },{
        name : "username",
        index : "username",
        sortable : false,
        width : 50,
        align : "center"
    },{
        name : "nativePlace",
        index : "nativePlace",
        sortable : false,
        width : 50,
        align : "center"
    },{
        name : "age",
        index : "age",
        sortable : false,
        width : 50,
        align : "center"
    },{
        name : "address",
        index : "address",
        sortable : false,
        width : 50,
        align : "center"
    },{
        name : "email",
        index : "email",
        sortable : false,
        width : 50,
        align : "center"
    },{
            name : "free",
            index : "free",
            sortable : false,
            width : 50,
            align : "center",
            formatter : function(cellvalue, options, rowdata){
                if(cellvalue==true){
                    return "空闲";
                }else{
                    return "忙碌";
                }
            }
        }];

    //新建一个数组，存放已勾选的id
    var SelectList = []//(用于记录被选中的行)

    var myJqGrid = null;
    $(document).ready(function () {
        myJqGrid = new MyJqGrid({
            jqGrid_id: 'table',
            data: "${ctxPath!}/sys/worker/status.json",
            isSubGrid: false,
            autowidth: true,
            shrinkToFit: true,
            autoScroll: true,
            colNames: colNames,
            colModel: colModel,
            onSelectAll: function (aRowids, status) {
                if (status) {
                    for (var i = 0; i < aRowids.length; i++) {
                        if (SelectList.indexOf(aRowids[i]) == -1) {//每一次勾选时，检查该行是否在SelectList中，
                            //若在，则在SelectList中删除该记录
                            //（翻页也会触发onselect事件，所以需检查该行是否在unselects中）
                            SelectList.push(aRowids[i]);
                        }
                    }
                } else {
                    for (var i = 0; i < aRowids.length; i++) {
                        if (SelectList.indexOf(aRowids[i]) > -1) {//每一次勾选时，检查该行是否在SelectList中，
                            //若在，则在SelectList中删除该记录
                            //（翻页也会触发onselect事件，所以需检查该行是否在unselects中）
                            SelectList.splice($.inArray(aRowids[i], SelectList), 1)
                        }
                    }
                }
            },
            gridComplete: function () {
                var ids = $("#table").jqGrid('getDataIDs');
                for (var i = 0; i < ids.length; i++) {
                    if ((SelectList.indexOf(ids[i]) > -1)) {
                        $("#table").jqGrid('setSelection', ids[i]);
                    }
                }
            },
            onSelectRow: function (rowid, status) {
                if (status) { // 每一次取消选中时，将该行id添加到SelectList中
                    if (SelectList.indexOf(rowid) == -1) {//每一次勾选时，检查该行是否在SelectList中，
                        //若在，则在SelectList中删除该记录
                        //（翻页也会触发onselect事件，所以需检查该行是否在unselects中）
                        SelectList.push(rowid);
                    }
                } else {
                    if (SelectList.indexOf(rowid) > -1) {//每一次勾选时，检查该行是否在SelectList中，
                        //若在，则在SelectList中删除该记录
                        //（翻页也会触发onselect事件，所以需检查该行是否在unselects中）
                        SelectList.splice($.inArray(rowid, SelectList), 1)
                    }
                }
            }
        })
    });

    function search(){
        myJqGrid.reloadGrid({"workerLevel":$("#workerLevel").val(),"education":$("#education").val(),"free":$("#free").val(),"keyword":$("#keyword").val()});
        return false;
    }


</script>
</body>
</html>